
var answer = parseInt(Math.random() * 98) +2;
var min = 1;
var max = 100;

while (true) {
    var n = Number(prompt('请猜测数字' + min + '~' + max));

    if (n <= min || n >= max) {
        alert('你输入的数字不在范围内');
        continue;
    }

    if (n > answer) {
        alert('你输入的数字太大了');
        max = n;
    } else if (n < answer) {
        alert('你输入的数字太小了');
        min = n;
    } else {
        alert('猜对了！');
        break;
    }
}